var Bui = Class.create();
Bui.prototype = {

	initialize:function(form, url){
		this.form = form || 'rootForm';
		this.url = url || '#';
	},

	loadRoot:function(){
		new Ajax.Request(this.url, {onSuccess: this.updateC.bindAsEventListener(this), parameters:{buiRoot:'true'}});
	},
	
	load: function(action){
		var params = $(this.form).serialize({getHash:true});
		params.buiLoad = true;
		if(action){
			params.buiAction = action;
		}
		new Ajax.Request(this.url, {onSuccess: this.updateC.bindAsEventListener(this), parameters:params});
	},
	
  	updateC: function(transport) {
		var response = transport.responseText || '';
		var regexp = new RegExp("<BUI (.*?)>([\\s\\S]*?)<\/BUI>");
		var match = regexp.exec(response);
		while(match){
			var id = match[1];
			var code = match[2];
			response = response.substring(match.index + match[0].length);
			var match = regexp.exec(response);
			$(id).replace(code);
		}
  	}
};